<?php
require('common_view_functions.php');

function without_time($dt_str) {
	$r = explode(' ', $dt_str);
	return $r[0];
}

function add_email($sender_name, $sender_email) {
	return ($sender_email == '') ? htmlspec($sender_name) : '<a href="mailto:' . $sender_email . '">' . htmlspec($sender_name) . '</a>';
}

function get_avatar_name($user_id, $rand = FALSE) {
	$fn = $_SERVER['DOCUMENT_ROOT'] . '/img/avatars/avt_' . $user_id . '_48x48.jpg';
	if(file_exists($fn)) {
		if($rand) {
			return 'avt_' . $user_id . '_48x48.jpg?R=' . rand();
		} else {
			return 'avt_' . $user_id . '_48x48.jpg';
		}
	} else {
		return 'avt_-1_48x48.jpg';
	}
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Blog 用户后台管理 - 查看悄悄话</title>
<link rel="shortcut icon" href="/img/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/css/mgmt.css" />
<link rel="stylesheet" type="text/css" href="/css/3rd/jqModal.css" />
</head>
<body id="bodyMsgs">
<div id="wrapper">
	<!-- header -->
	<?php require('common_header.php'); ?>
	<!-- /header -->
	<div id="body">
		<div id="side">
			<div id="btnReturnToListDiv" class="sim_button"><a href="<?php echo('/' . $blogger_uri . '/mgmt/messages'); ?>">返回悄悄话列表</a></div>
		</div>
		<div id="main">
			<div id="divMessage">
				<div id="rmHead">
					<img alt="" src="/img/avatars/<?php echo(get_avatar_name($message_details->from_blogger_id)); ?>" class="msg_avatar" />
					<?php echo(add_email($message_details->sender_name, $message_details->sender_email)); ?>
					@
					<?php echo($this->common->NicerTime($message_details->sent_time)); ?>
					<h3><?php echo($message_details->title); ?></h3>
				</div>
				<div id="rmContent"><?php echo($message_details->content); ?></div>
				<div id="rmOper">
					<?php if($message_details->from_blogger_id > 0) { ?><input type="button" id="btnShowReply" name="btnShowReply" class="button" value="回复" /><?php } ?>
				</div>
				<div id="replyPMBox" style="display:none;">
					<form id="frmReplyPM">
						<p><input type="text" id="txtReplyPMTitle" class="textBox" maxlength="64" style="width:36em;" /></p>
						<p><textarea id="txtReplyPMContent" class="textBox" cols="32" rows="5" style="width:36em;"></textarea></p>
						<p><input type="button" id="btnReplyPM" name="btnReplyPM" class="button" value="发送" /></p>
						<input type="hidden" id="hidReplyTo" value="<?php echo($message_details->from_blogger_id); ?>" />
					</form>
				</div>
			</div>
		</div>
		<div class="z"></div>
	</div>
	<!-- footer -->
	<?php require('common_footer.php'); ?>
	<!-- /footer -->
</div>

<!-- JS -->
<script type="text/javascript" src="/js/3rd/jquery.pack.js"></script>
<script type="text/javascript" src="/js/3rd/jqModal.js"></script>
<script type="text/javascript" src="/js/3rd/json2.js"></script>
<script type="text/javascript">
<!--
var g_userSiteRoot = "<?php echo('/' . $blogger_uri); ?>";

function replyPMCallback(rdata) {
	$("#ajaxLoading").hide();
	rdata = rdata.split("_");
	if(rdata[0] != "SUCC") {
		alert("Operation failed!");
		return;
	} else {
		alert("悄悄话已送出。");
		location.href = g_userSiteRoot + "/mgmt/messages";
	}
}

$(document).ready(function() {
	$("#btnShowReply").click(function() {
		var oriTitle = $("#rmHead h3").html();
		$("#txtReplyPMTitle").val("Re: " + oriTitle);
		$("#replyPMBox").show();
		$("#txtReplyPMContent").focus();
	});
	
	$("#btnReplyPM").click(function() {
		var to_blogger_id = $("#hidReplyTo").val();
		
		var repTitle = $("#txtReplyPMTitle").val();
		var repContent = $("#txtReplyPMContent").val();
		if(repTitle == "" || repContent == "") {
			alert("悄悄话标题和内容不能为空！");
			return;
		}
		
		$("#ajaxLoading").show();
		var pm_data = {
			"to_blogger_id": to_blogger_id,
			"title": repTitle,
			"content": repContent
		};
		$.post(g_userSiteRoot + "/mgmt/messages", {
			"hidIsPostBack": "ja",
			"operation": "send_pm",
			"posted_data": JSON.stringify(pm_data)
		}, replyPMCallback);
	});
});
// -->
</script>
<!-- /JS -->

<div id="ajaxLoading"><img alt="Loading..." src="<?php echo(base_url() . 'img/ajax_loading.gif'); ?>" border="0" width="24" height="24" /></div>
</body>
</html>